package com.zhaohanlin.start;

import org.junit.Test;

/**
 * @author zhaohanlin
 */

public class ExtendTest {
    static class Employee {
        private Double sal;

        public Employee() {
            System.out.println("Employee()...");
        }

        // alt + insert
        public Double getSal() {
            return sal;
        }

        public void setSal(Double sal) {
            this.sal = sal;
        }
    }

    static class Manager extends Employee{
        private Double bonus;

        public Manager(){
            // 子类构造器首行默认 `super()`，即实例化任何类时，都一定是先调其父类构造器，再调用子类构造器。
            System.out.println("Manager()...");
        }

        public Double getBonus() {
            return bonus;
        }

        public void setBonus(Double bonus) {
            this.bonus = bonus;
        }

        public Double total(){
            // 子类中可使用 `super.方法()` 调用父类的普通方法。
            return this.bonus + super.getSal();
        }

    }

    @Test
    public void total() {
        Manager zhaosi = new Manager();
        zhaosi.setSal(5000.0);
        zhaosi.setBonus(2000.0);
        System.out.println(zhaosi.total());
    }
}
